
// === uuQuery+ ===
// depend: uuMeta, uuQuery
(function() {
var _query = uuQuery,
    _mm = uuMeta,
    _int = parseInt,
    _ie = _mm.ie,
    _runstyle = _mm.runstyle,
    _mix = _mm.mix,
    TYPE = "type";

// === jQuery Selectors ====================================
_mix(_query.filters, {
  first:    [0x01, _query.childFilter],
  last:     [0x02, _query.childFilter],
  even:     [0x80, even],
  odd:      [0x81, odd],
  eq:       [0x82, eq],
  gt:       [0x83, jFilter],
  lt:       [0x84, jFilter],
  parent:   [0x85, jFilter],
  header:   [0x86, jFilter],
  input:    [0x87, jFilter],
  button:   [0x88, jFilter],
  text:     [0x89, jFilter],
  password: [0x8a, jFilter],
  radio:    [0x8b, jFilter],
  checkbox: [0x8c, jFilter],
  submit:   [0x8d, jFilter],
  image:    [0x8e, jFilter],
  reset:    [0x8f, jFilter],
  file:     [0x90, jFilter],
  hidden:   [0x91, jFilter],
  visible:  [0x92, jFilter],
  selected: [0x93, jFilter]
});

function jFilter(fid, negate, elms, pseudo, value, tags, contentType) {
  var rv = [], ri = -1, v, i = 0, iz = elms.length, ok, rex;

  function hidden(elm) {
    var cs = _ie ? elm[_runstyle]
                 : _runstyle(elm, "");
    return cs.display === "none" || cs.visibility === "hidden";
  }

  for(; i < iz; ++i) {
    v = elms[i];
    ok = 0;
    switch (fid) {
    case 0x83:  ok = i >= _int(value) + 1; break;
    case 0x84:  ok = i <= _int(value) - 1; break;
    case 0x85:  ok = !!v.firstChild; break;
    case 0x86:  rex = RegExp("h[1-6]", contentType === 1 ? "i" : "");
                ok = rex.test(v.tagName); break;
    case 0x87:  rex = RegExp("(input|textarea|select|button)",
                             contentType === 1 ? "i" : "");
                ok = rex.test(v.tagName) || v[TYPE] === "button"; break;
    case 0x88:  rex = RegExp("button", contentType === 1 ? "i" : "");
                ok = rex.test(v.tagName) || v[TYPE] === "button"; break;
    case 0x89:  ok = v[TYPE] === "text"; break;
    case 0x8a:  ok = v[TYPE] === "password"; break;
    case 0x8b:  ok = v[TYPE] === "radio"; break;
    case 0x8c:  ok = v[TYPE] === "checkbox"; break;
    case 0x8d:  ok = v[TYPE] === "submit"; break;
    case 0x8e:  ok = v[TYPE] === "image"; break;
    case 0x8f:  ok = v[TYPE] === "reset"; break;
    case 0x90:  ok = v[TYPE] === "file"; break;
    case 0x91:  ok = (v[TYPE] === "hidden" || hidden(v)); break;
    case 0x92:  ok = (v[TYPE] !== "hidden" && !hidden(v)); break;
    case 0x93:  ok = !!v.selected; break;
    }
    if (ok ^ negate) {
      rv[++ri] = v;
    }
  }
  return rv;
}

function even(fid, negate, elms, pseudo, value, tags, contentType) {
  var fl = _query.filters["nth-child"];
  return fl[1](fl[0], negate, elms, pseudo, "odd", tags, contentType);
}

function odd(fid, negate, elms, pseudo, value, tags, contentType) {
  var fl = _query.filters["nth-child"];
  return fl[1](fl[0], negate, elms, pseudo, "even", tags, contentType);
}

function eq(fid, negate, elms, pseudo, value) {
  var v, ok = 0;
  if ( (v = elms[_int(value)]) ) {
    ok = 1;
  }
  return (ok ^ negate) ? [v] : [];
}

// --- initialize ---

// --- export ---

})(); // uuQuery+ scope
